package com.atguigu.jxc.controller;

import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SuppliersService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class SuppliersController {

    @Autowired
    private SuppliersService suppliersService;

    @PostMapping("/supplier/list")
    public Map<String, Object> queryPage(@RequestParam("page") Integer page,
                                         @RequestParam("rows") Integer rows,
                                         @RequestParam("supplierName") String supplierName) {

        Map<String, Object> result =new HashMap<>();

        PageInfo<Supplier> pageInfo = suppliersService.queryPage(page, rows, supplierName);
        long total = pageInfo.getTotal();
        List<Supplier> supplierList = pageInfo.getList();

        result.put("total",total);
        result.put("rows",supplierList);

        return result;
    }

}
